package Internet.Program;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Scanner;

/**
 * @Author: Jason
 * @ClassName: web01
 * @Description: 网络编程 测试ip
 * @Package：Internet.Program
 * @Project：javaDemo
 * @name：web01
 * @Filename：web01
 **/

public class web01 {
    public static void main(String[] args) {
//        Scanner scanner = new Scanner(System.in);
//        String name = scanner.nextLine();
//        int number = scanner.nextInt();
//        System.out.println(name);
//        System.out.println(number);

        try {
            //查询本机地址
            InetAddress inetAddress = InetAddress.getByName("127.0.0.1");
            System.out.println(inetAddress);
            InetAddress inetAddress2 = InetAddress.getLocalHost();System.out.println(inetAddress);
            System.out.println(inetAddress2);
            InetAddress inetAddress3 = InetAddress.getByName("localhost");
            System.out.println(inetAddress3);
            //查询网站ip地址
            InetAddress inetAddress1 = InetAddress.getByName("www.baidu.com");
            System.out.println(inetAddress1);

            //常用方法
            System.out.println(inetAddress1.getAddress());
            //获得规范名字（IP）
            System.out.println(inetAddress1.getCanonicalHostName());
            //IP
            System.out.println(inetAddress1.getHostAddress());
            //域名
            System.out.println(inetAddress1.getHostName());

        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }

}
